﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageLateness : Objective
    {
        public AverageLateness()
            : base()
        {
        }
        public AverageLateness(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {
            double averageLateness = 0;
            double totalLateness = 0;

            int lateness = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                lateness = order.EndDate - order.DueDate;
                totalLateness = totalLateness + lateness;
            }

            averageLateness = totalLateness / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageLateness,2);


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderDueDateValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
        }


        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Lateness";
                aboutInfo.Guid = new Guid("{90E58D03-6DB3-4153-AFFD-DD1A8E727666}");
                aboutInfo.Description = Resources.AverageLatenessDescription;
                return aboutInfo;
            }
        }

    }
}
